package com.hubujun.driverlicense.network;

import android.content.Context;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import com.hubujun.driverlicense.util.Ln;
import com.hubujun.driverlicense.util.ShowUtils;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2016/5/28 0028.
 */
public class PostTest {
    private static final String URL_REQUEST_QUESTIONS = "http://api2.juheapi.com/jztk/query";

    public static void requestQuestions(final Context context) {
        RequestQueue mQueue = Volley.newRequestQueue(context);

        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, URL_REQUEST_QUESTIONS, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                Ln.d("PostTest onResponse response=%s", response);
                ShowUtils.toastShortMsg(context, response.toString());
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Ln.e("PostTest onErrorResponse error message=%s,error=%s", error.getMessage(), error);
                ShowUtils.toastShortMsg(context, error.getMessage());
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> map = new HashMap<String, String>();
                map.put("key", "9fccfbaf3eb0a40379c4a35df28314b2");
                map.put("subject", "1");
                map.put("model", "c1");
                map.put("testType", "rand");
                return map;
            }
        };
        mQueue.add(jsonObjectRequest);

    }
}
